define([
  'views/Form',
  'hbs!template/users/user-profile'
], function(Form, template){
  var UserProfile = Form.extend({
    template: template,
    events: {
      "click button[name=save]":	"save",
      "click button[name=cancel]":	"back",
      "submit form":			"stopSubmit"
    },

    initialize: function(options) {
      Form.prototype.initialize.call(this, options);
      this.model.bind("change", this.render, this);
    },
    
    render: function() {
      Form.prototype.render.call(this);
      this.$("#password").click(function() {
        $(this).select();
      });

      return this; 
    },

    save: function() {
      this.Logger.debug("User profile form", this.getObjectFromForm(this.$("form")));
      this.model.save(this.getObjectFromForm(this.$("form")));
    }
  });

  return UserProfile;
});